package EVO.afterReturning;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

import java.util.Date;

@Aspect
public class MyAspect {
    @AfterReturning(value = "execution(String *..*.doOther(..))",returning = "str")
    public void myAfterReturning(String str){
        System.out.println("后置通知执行....返回值："+str);
        str = "wangwu";
    }


    @AfterReturning(value = "execution(Student *..*.doOther2(..))",returning = "stu")
    public void myAfterReturning2(Student stu){
        System.out.println("后置通知执行....返回值："+stu);
        stu.setName("lisi");
    }

    @Around(value = "execution(String *..*.doFirst(..))")
    public Object myAround(ProceedingJoinPoint pjp){
        Object result = null;
        System.out.println("环绕通知目标方法前调用......."+new Date());

        try {
            result = pjp.proceed();
            System.out.println("环绕通知目标方法后调用.......提交事务");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }

        return result;
    }

}
